package movee.clickhouse.client;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

@SpringBootApplication
@Slf4j
public class ClickhouseClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClickhouseClientApplication.class, args);
    }


    @Bean
    public CommandLineRunner runner() {
        return (args) -> {
            log.info("a");
            Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
            String url = "jdbc:clickhouse://10.131.21.20:8123/baidu_network_avail";

            Connection conn = DriverManager.getConnection(url);
            log.info("c");
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery("select * from cluster");

            while (rs.next()) {
                log.info("idc: {}, cluster: {}", rs.getString(2), rs.getString(3));
            }

        };
    }

}
